﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using Common; 

public partial class temp_productlist : System.Web.UI.Page
{
    public string PaginationBar = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        if (!IsPostBack)
        {
            ProductListDataBind();
        }
    }
    #region 商品列表
    void ProductListDataBind()
    {
        string urlStr = "productlist.aspx?";

        StringBuilder SQL = new StringBuilder();
        SQL.Append(" AND DeletionStateCode = 0");
        if (RequestBase.GetQueryString("qtype") != "" && Utils.IsNumber(RequestBase.GetQueryString("categorynumber")))
        {
            SQL.Append(" AND CategoryNumber LIKE '" + RequestBase.GetQueryString("categorynumber") + "%'");
        }

        #region 分页
        DBUtility.Pagination pagination = new DBUtility.Pagination();
        /// 页码
        if (RequestBase.GetString("page") != "" && Utils.IsNumber(RequestBase.GetString("page")))
            pagination.Sequence = Convert.ToInt32(RequestBase.GetString("page"));
        else
            pagination.Sequence = 1;

        /// 每页显示记录数
        int pagesize = 12;
        if (RequestBase.GetString("pageSize") != "" && Utils.IsNumber(RequestBase.GetString("pageSize")))
            pagesize = int.Parse(RequestBase.GetString("pageSize"));

        /// 排序方式
        string sortType = " ORDER BY ProductNumber ASC";
        if (RequestBase.GetString("pageSize") != "" && Utils.IsNumber(RequestBase.GetString("pageSize")))
        {
            switch (RequestBase.GetString("pageSize"))
            {
                case "30":
                    sortType = " ORDER BY Price ASC";
                    break;
                case "40":
                    sortType = " ORDER BY Price DESC";
                    break;
                default:
                    sortType = " ORDER BY ProductNumber ASC";
                    break;
            }
        }

        if (RequestBase.GetString("upcount") != "" && Utils.IsNumber(RequestBase.GetString("upcount")))
            pagination.PageUpCount = Convert.ToInt32(RequestBase.GetString("upcount"));

        if (RequestBase.GetString("direction") == "next")
            pagination.Direction = "next";
        else
            pagination.Direction = "prev";

        pagination.PageBarCount = 8;
        pagination.UrlStr = urlStr;
        pagination.PageSize = pagesize;
        pagination.Primarykey = "ProductId";
        pagination.SearchField = "*";
        pagination.TableName = "vw_ProductBase";
        pagination.ItemUnit = "件商品";
        pagination.SearchSentence = SQL.ToString();
        pagination.SortSentence = sortType;

        rptProductList.DataSource = pagination.GetDataTable();
        rptProductList.DataBind();

        pagination.GoNumeberPageBarCn2();
        PaginationBar = pagination.PageBar;
        #endregion
    }
    #endregion
}